<template>
  <div class="operation_box tree-container mytree">
    <el-tree
      :data="data"
      node-key="label"
      class="tree"
      :props="defaultProps"
      :default-expanded-keys="['首页']"
      draggable
      @node-click="TreeCk"
      @node-drop="nodeDrop"
    >
    </el-tree>
  </div>
</template>


<script>
export default {
  methods: {
    nodeDrop(node, jiedian, weizhi, event) {
      console.log(node, jiedian);
    },
    // 节点点击，可以获取该节点的基本信息
    TreeCk(node) {
      //   console.log(node, node.children);
    },
    // 拖拽时判定目标节点能否被放置。
    //draggingNode(拖拽的节点)
    //dropNode(放置的目标节点)
    //type 参数有三种情况：'prev'、'inner' 和 'next'，分别表示
    //放置在目标节点前、插入至目标节点和放置在目标节点后
    allowDrop(draggingNode, dropNode, type) {
      if (draggingNode.level == "1") {
        return false;
      } else {
        if (draggingNode.level == dropNode.level) {
          return type === "prev" || type === "next";
        } else if (draggingNode.level == dropNode.level + 1) {
          return type === "inner";
        } else {
          return false;
        }
      }
    },
    allowDrag() {},
  },
  data() {
    return {
      data: [
        {
          id: "1",
          label: "首页",
          children: [
            {
              id: "1-1",
              label: "党建头条",
              children: [
                {
                  id: "1-1-1",
                  label: "中央声音",
                },
                {
                  id: "1-1-2",
                  label: "省委部署",
                },
                {
                  id: "1-1-3",
                  label: "组工动态",
                },
                {
                  id: "1-1-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-2",
              label: "热点资讯",
              children: [
                {
                  id: "1-2-1",
                  label: "中央声音",
                },
                {
                  id: "1-2-2",
                  label: "省委部署",
                },
                {
                  id: "1-2-3",
                  label: "组工动态",
                },
                {
                  id: "1-2-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-3",
              label: "通知公告",
              children: [
                {
                  id: "1-3-1",
                  label: "中央声音",
                },
                {
                  id: "1-3-2",
                  label: "省委部署",
                },
                {
                  id: "1-3-3",
                  label: "组工动态",
                },
                {
                  id: "1-3-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-4",
              label: "党建工作",
              children: [
                {
                  id: "1-4-1",
                  label: "中央声音",
                },
                {
                  id: "1-4-2",
                  label: "省委部署",
                },
                {
                  id: "1-4-3",
                  label: "组工动态",
                },
                {
                  id: "1-4-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-5",
              label: "干部工作",
              children: [
                {
                  id: "1-5-1",
                  label: "中央声音",
                },
                {
                  id: "1-5-2",
                  label: "省委部署",
                },
                {
                  id: "1-5-3",
                  label: "组工动态",
                },
                {
                  id: "1-5-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-6",
              label: "人才工作",
              children: [
                {
                  id: "1-6-1",
                  label: "中央声音",
                },
                {
                  id: "1-6-2",
                  label: "省委部署",
                },
                {
                  id: "1-6-3",
                  label: "组工动态",
                },
                {
                  id: "1-6-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-7",
              label: "公务员工作",
              children: [
                {
                  id: "1-2-1",
                  label: "中央声音",
                },
                {
                  id: "1-2-2",
                  label: "省委部署",
                },
                {
                  id: "1-2-3",
                  label: "组工动态",
                },
                {
                  id: "1-2-4",
                  label: "市县快讯",
                },
              ],
            },
            {
              id: "1-8",
              label: "专题",
              children: [
                {
                  id: "1-8-1",
                  label: "中央声音",
                },
                {
                  id: "1-8-2",
                  label: "省委部署",
                },
                {
                  id: "1-8-3",
                  label: "组工动态",
                },
                {
                  id: "1-8-4",
                  label: "市县快讯",
                },
              ],
            },
          ],
        },
      ],
      defaultProps: {
        // 用于修改节点指定标签的属性值
        children: "children",
        label: "label",
      },
    };
  },
};
</script>




<style scoped>
.tree-container /deep/ .el-tree-node__expand-icon.expanded {
  -webkit-transform: rotate(90deg);
  transform: rotate(90deg);
}

.tree-container /deep/ .el-icon-caret-right:before {
  content: "\e791";
  font-size: 18px;
}

.tree-container /deep/ .el-tree-node__expand-icon {
  margin-left: 15px;
  padding: 0px;
}

.tree-container /deep/ .el-tree-node__expand-icon.is-leaf {
  margin-left: 0px;
}

.tree-container /deep/ .el-tree-node {
  position: relative;
  padding-left: 16px;
}

.tree-container /deep/ .el-tree-node__children {
  padding-left: 16px;
}

.tree-container /deep/ .el-tree > .el-tree-node:before {
  border-left: none;
}

.tree-container /deep/ .el-tree > .el-tree-node:after {
  border-top: none;
}
.tree-container /deep/ .el-tree > .el-tree-node:before {
  border-left: none;
}

.tree-container /deep/ .el-tree > .el-tree-node:after {
  border-top: none;
}

.tree-container /deep/ .el-tree-node:before {
  content: "";
  left: 10px;
  position: absolute;
  right: auto;
  border-width: 1px;
}

.tree-container /deep/ .el-tree-node:after {
  content: "";
  left: 10px;
  position: absolute;
  right: auto;
  border-width: 1px;
}

.tree-container /deep/ .el-tree-node:before {
  border-left: 1px solid #e6e6e6;
  bottom: 0px;
  height: 100%;
  top: -19px;
  width: 1px;
}

.tree-container /deep/ .el-tree-node:after {
  border-top: 1px solid #e6e6e6;
  height: 25px;
  top: 20px;
  width: 20px;
}

.el-tree-node :last-child:before {
  height: 40px;
}

.tree-container {
  margin: 10px;
}
.tree-container /deep/ .el-tree .el-tree-node {
  position: relative;
}
.tree-container /deep/ .el-tree-node .el-tree-node__content {
  height: 40px;
  padding-left: 18px;
}
.tree-container /deep/ .el-tree-node .el-tree-node__content::before {
  border-left: 1px solid #e6e6e6;
  height: 100%;
  top: 0;
  width: 1px;
  margin-left: 1px;
  margin-top: 0px;
  z-index: 8;
}
.tree-container
  /deep/
  .el-tree-node
  .el-tree-node__children
  .el-tree-node__content::before {
  border-left: 0px solid #e6e6e6;
  height: 100%;
  top: 0;
  width: 1px;
  margin-left: 1px;
  margin-top: 0px;
  z-index: 8;
}

.tree-container /deep/ .el-tree-node .el-tree-node__content::after {
  border-top: 1px solid #e6e6e6;
  height: 1px;
  top: 18px;
  width: 13px;
  margin-left: 1px;
  z-index: 8;
}

.tree-container
  /deep/
  .el-tree-node
  .el-tree-node__children
  .el-tree-node__content::after {
  border-top: 0px solid #e6e6e6;
}

.tree-container .el-tree-node .el-tree-node__content::before,
.tree-container .el-tree-node .el-tree-node__content::after {
  content: "";
  position: absolute;
  right: auto;
}
</style>






<!-- 不好看 -->
<!-- <style scoped>
.tree-container {
  overflow: hidden;
}
.tree /deep/ .el-tree-node {
  position: relative;
  padding-left: 0;
}

.tree /deep/ .el-tree-node__children {
  padding-left: 16px;
}

.tree /deep/ .el-tree-node :last-child:before {
  height: 12px;
}

.tree /deep/ .el-tree > .el-tree-node:before {
  border-left: none;
}

.tree-container /deep/ .el-tree > .el-tree-node:after {
  border-top: none;
}

.tree /deep/ .el-tree-node:before {
  content: "";
  left: -4px;
  position: absolute;
  right: auto;
  border-width: 1px;
  border-left: 1px dashed #4386c6;
  bottom: 0px;
  height: 100%;
  top: 0px;
  width: 1px;
}

.tree /deep/ .el-tree-node:after {
  content: "";
  left: -4px;
  position: absolute;
  right: auto;
  border-width: 1px;
  border-top: 1px dashed #4386c6;
  height: 20px;
  top: 12px;
  width: 10px;
}
</style> -->


<!-- 用起来有问题 -->
<!-- Add "scoped" attribute to limit CSS to this component only -->
<!-- <style scoped lang="less">
.operation_box {
  /deep/ .tree {
    color: #595959;
    background: transparent;

    /* 树形结构节点添加连线 */
    .el-tree-node {
      position: relative;
      padding-left: 16px;

      .el-tree-node__content {
        height: 18px;
        padding-top: 16px;
        padding-left: 0 !important;

        .el-tree-node__expand-icon {
          background: url(../assets/logo.png) no-repeat;
          display: inline-block;
          width: 16px;
          height: 16px;
          padding: 0;

          &.expanded {
            transform: none;
            background: url(../assets/logo.png) no-repeat;
          }

          &::before {
            content: "";
          }

          &.is-leaf {
            display: none;
          }
        }

        .el-tree-node__label {
          margin-left: 10px;
        }
      }

      &:last-child:before {
        height: 50px;
      }

      &:before {
        content: "";
        left: -4px;
        position: absolute;
        right: auto;
        border-width: 1px;
        border-left: 1px solid #bbbbbb;
        bottom: 0px;
        height: 100%;
        top: -26px;
        width: 1px;
      }

      &:after {
        content: "";
        left: -4px;
        position: absolute;
        right: auto;
        border-width: 1px;
        border-top: 1px solid #bbbbbb;
        height: 20px;
        top: 24px;
        width: 18px;
      }
    }

    & > .el-tree-node {
      & > .el-tree-node__content {
        .el-tree-node__expand-icon {
          background-image: url(../assets/logo.png) !important;
        }
      }

      &::after {
        border: 0px solid;
      }
    }

    .el-tree-node__children {
      padding-left: 12px;
    }
  }
}
</style>
 -->
